package com.guoyw.seata.storage.service.impl;

import com.baomidou.mybatisplus.service.IService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.guoyw.seata.common.dto.CommodityDTO;
import com.guoyw.seata.common.enums.RspStatusEnum;
import com.guoyw.seata.common.response.ObjectResponse;
import com.guoyw.seata.storage.entity.TStorage;
import com.guoyw.seata.storage.mapper.TStorageMapper;
import com.guoyw.seata.storage.service.ITStorageService;
import org.apache.dubbo.config.annotation.Service;

/**
 * author: guoyw
 * create: 2020-09-19 17:35
 **/
@Service
public class ITStorageServiceImpl extends ServiceImpl<TStorageMapper,TStorage> implements ITStorageService {
 
 
  @Override
  public ObjectResponse decreaseStorage(CommodityDTO commodityDTO){
    int storage = baseMapper.decreaseStorage(commodityDTO.getCommodityCode(), commodityDTO.getCount());
    ObjectResponse<Object> response = new ObjectResponse<>();
    if (storage > 0){
      response.setStatus(RspStatusEnum.SUCCESS.getCode());
      response.setMessage(RspStatusEnum.SUCCESS.getMessage());
      return response;
    }
  
    response.setStatus(RspStatusEnum.FAIL.getCode());
    response.setMessage(RspStatusEnum.FAIL.getMessage());
    return response;
  }
}
